<?php use_javascript('/pwCorePlugin/js/jquery-tools/jquery.busy.min.js') ?>
<?php include_stylesheets_for_form($form) ?>
<?php include_javascripts_for_form($form) ?>
<?php use_helper('Tooltip','LetsManager','jQuery') ?>

<script type="text/javascript">
jQuery().ready(function()
{
  jQuery('.buttonSubmitLoading').click(function() { 
    jQuery(this).busy({ img : "<?php echo image_path('/pwCorePlugin/images/indicator.gif') ?>", title: "Veuillez patentier ..."}); 
    jQuery(this).after("<span style='color: green;'>Enregistrement en cours ...</span>");
  }); 
  jQuery(".choice_validation_partner").change(function(){
    updateValidationPanel();
  });
  updateValidationPanel();
  
  //jQuery(".validationHidden").css('visibility','visible');
});
function updateValidationPanel()
{
  var state = jQuery(".choice_validation_partner:checked").val();
  if(state)
  {
    jQuery(".validationHidden").show();
  }
  else
  {
    jQuery(".validationHidden").hide();
  }
}
</script>
<style>

</style>
<?php include_component('letsMember','moneySentence') ?>
<br />
<br />
<form
  action="<?php echo url_for('@lets_exchange_'.($form->getObject()->isNew() ? 'create' : 'update?id='.$form->getObject()->getId())) ?>"
  method="post"><?php if (!$form->getObject()->isNew()): ?> <input
  type="hidden" name="sf_method" value="put" /> <?php endif ?>

<table class="formtable" summary="Register a transaction" width="650px">

  <!-- Form body, displays fields -->

  <tbody>
  <?php echo $form->renderGlobalErrors() ?>
  <?php if($form->isNew()): ?>
    <tr>
      <th width="36%"><?php echo $form['other_user_id']->renderLabel() ?></th>
      <td><?php echo $form['other_user_id'] .' '. $form['other_user_id']->renderError() ?></td>
    </tr>
  <?php else: ?>
    <tr>
      <th>Partenaire</th>
      <td><?php echo lets_format_member($other_member,true) ?></td>
    </tr>
  <?php endif ?>
  <tr>
    <th><?php echo $form['name']->renderLabel() ?></th>
    <td><?php echo $form['name'] .' '. $form['name']->renderError() ?></td>
  </tr>
  <tr>
    <th><?php echo $form['category_id']->renderLabel() ?></th>
    <td><?php echo $form['category_id'] ?> <?php echo $form['category_id']->renderError() ?></td>
  </tr>
  <tr>
    <th><?php echo $form['amount']->renderLabel() ?></th>
    <td><?php echo $form['amount'] .' '. lets_money_name() .' '. $form['amount']->renderError() ?></td>
  </tr>
  <?php if($form->isNew()): ?>
    <tr>
      <th><?php echo $form['date_exchange']->renderLabel() ?></th>
      <td><?php echo $form['date_exchange'] .' '. $form['date_exchange']->renderError() ?></td>
    </tr>
    <tr>
      <th><?php echo $form['type']->renderLabel() ?></th>
      <td><?php echo $form['type'] .' '. $form['type']->renderError() ?></td>
    </tr>
    <tr>
      <th><?php echo $form['validation_partner']->renderLabel() ?></th>
      <td><?php echo $form['validation_partner'] .' '. $form['validation_partner']->renderError() ?></td>
    </tr>
    <tr class="subitem validationHidden">
      <th colspan="2" >Validation direct par le/la partenaire</th>
    </tr>
    <tr class="validationHidden">
      <td colspan="2">Si votre partenaire est à coté il lui suffit de saisir le mot de passe de son compte ci dessous. 
      L'échange sera alors directement accepté et aucune étape de validation ne sera nécessaire.</td>
    </tr>
    <tr class="validationHidden">
      <th><?php echo $form['partner_password']->renderLabel() ?></th>
      <td><?php echo $form['partner_password'] .' '. $form['partner_password']->renderError() ?></td>
    </tr>
  <?php else: ?>
    <tr>
      <th>Et vous êtes</th>
      <td><?php echo $form->getObject()->getPaymentTypeString($sf_user->getUserId()) ?></td>
    </tr>
  <?php endif ?>

  </tbody>
  <tfoot>
    <tr >
      <td colspan="2" id="tdCellSubmit"><?php echo $form->renderHiddenFields() ?> 
      <?php echo link_to('Annuler',  '@lets_user_asksAndOffers', array('class' => 'blue button')) ?>
      <input type="submit" value="Sauvegarder" class="blue button buttonSubmitLoading"/></td>
    </tr>
  </tfoot>
</table>
</form>
